//
// Created by Semir on 2020/4/26.
//

#include <iostream>
#include <algorithm>

using namespace std;

struct Milk {
    int price;
    int count;
};

const int MAX_M = 5005;
int n, m;
Milk* milks[MAX_M];

bool cmp(Milk* milk1, Milk* milk2) {
    return milk1->price < milk2->price;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        milks[i] = new Milk;
        cin >> milks[i]->price >> milks[i]->count;
    }
    sort(milks, milks + m, cmp);
    int cost = 0;
    for (int i = 0; i < m && n > 0; i++) {
        if (n > milks[i]->count) {
            n -= milks[i]->count;
            cost += milks[i]->price * milks[i]->count;
        } else {
            cost += milks[i]->price * n;
            n = 0;
        }
    }
    cout << cost << endl;
    return 0;
}